//动态交互
function JYUrl(cName, aName, args) {
	var sUrl = "http://" + location.hostname + "/" + cName + "/" + aName;
	if (args != undefined) {
		for (k in args) {
			sUrl += "/" + k + "-" + args[k];
		}
	}

	return (sUrl + ".html").toLowerCase();
}

function text_tips(id, str) {
	var obj = $("#" + id);
	obj.blur(function() {
		var objVal = $.trim(obj.val());
		if (objVal == "") {
			obj.val(str);
			obj.css('color', '#999999');
		}
	});

	obj.focus(function() {
		var objVal = $.trim(obj.val());
		if (objVal == str)
			obj.val("");
	});
}

/* 互动样式 */
function showmsg(id, msg, num) {
	$('#' + id + '_msg').html(msg);
	switch (num) {
	case 1:
		$('#' + id + '_msg').removeClass();
		$('#' + id + '_msg').addClass('empty');
		break;
	case 2:
		$('#' + id + '_msg').removeClass();
		$('#' + id + '_msg').addClass('fine');
		break;
	case 7:
		if (msg != '&nbsp;' && msg != '')
			$('#' + id + '_msg').css('display', '');
		break;
	default:
		$('#' + id + '_msg').removeClass();
		$('#' + id + '_msg').addClass('import');
	}
}

/* 本月预约和本月放号排名切换效果 */
function twotabs() {
	// 选项卡切换
	var a1 = $('#sc_f0');
	var a2 = $('#sc_f1');
	var con1 = $('#sc_con0');
	var con2 = $('#sc_con1');
	a1.mouseover(function() {
		a1.css('cursor', 'pointer');
		a1.parent().removeClass('actived2').addClass('actived1');
		con1.show();
		con2.hide();
	});
	a2.mouseover(function() {
		a2.css('cursor', 'pointer');
		a1.parent().removeClass('actived1').addClass('actived2');
		con2.show();
		con1.hide();
	});
}

// 收展
function drawContent(a, object, height) {
	var title = $(a).text();
	if (title == '展开') {
		$('#' + object).css("height", "");
		title = '收缩';
	} else {
		$('#' + object).css("height", ' ' + height + 'px');
		title = '展开';
	}
	$(a).text(title);
}

// 加载医生排班数据
function loadSectionSchData(uid, depid, bDate) {
	// var schBox = $("#schmast");
	// var url =
	// JYUrl("dep","getschmast",{"uid":uid,"depid":depid,"date":bDate});
	var url = sUrl = "http://" + location.hostname
			+ ":8080/ReserveSystemPortal" + "/section.json";
	var time = {
		"am" : "上午",
		"pm" : "下午"
	};
	var weeks = {
		1 : '星期一',
		2 : '星期二',
		3 : '星期三',
		4 : '星期四',
		5 : '星期五',
		6 : '星期六',
		7 : '星期日'
	};
	var html = ""; // "<div class=\"ajax2login\" style=\"
	// height:678px;width:763px;\">";
	$
			.getJSON(
					url,
					function(json) {
						$("#lastdate").val(json.last);
						$("#nextdate").val(json.next);
						// @ 判断是否需要隐藏上周链接
						if ($("#a_last").length > 0) {
							if (contrast(json.date[0], $("#a_last")
									.attr('name'))) {
								$("#a_last").css('display', '');
							} else {
								$("#a_last").css('display', 'none');
							}
						}
						html += "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"1\" class=\"paiban paiban_1\">"
								+ "<tr><th>"
								+ (json.yuyue_to ? "科室" : "医生")
								+ "</th><th>时间</th>"
								+ "<th width=\"80\">"
								+ weeks[json.week[0]]
								+ "<br>"
								+ json.date[0].substr(5)
								+ "</th>"
								+ "<th width=\"80\">"
								+ weeks[json.week[1]]
								+ "<br>"
								+ json.date[1].substr(5)
								+ "</th>"
								+ "<th width=\"80\">"
								+ weeks[json.week[2]]
								+ "<br>"
								+ json.date[2].substr(5)
								+ "</th>"
								+ "<th width=\"80\">"
								+ weeks[json.week[3]]
								+ "<br>"
								+ json.date[3].substr(5)
								+ "</th>"
								+ "<th width=\"80\">"
								+ weeks[json.week[4]]
								+ "<br>"
								+ json.date[4].substr(5)
								+ "</th>"
								+ "<th width=\"80\">"
								+ weeks[json.week[5]]
								+ "<br>"
								+ json.date[5].substr(5)
								+ "</th>"
								+ "<th width=\"80\">"
								+ weeks[json.week[6]]
								+ "<br>"
								+ json.date[6].substr(5)
								+ "</th>"
								+ "</tr>";
						for (i in json.doc) {
							dRec = json.doc[i];
							var docid = json.doc[i].doctor_id;

							// 不显示没有排班的医生
							if (!json.sch
									|| !json.sch[docid]
									|| !(json.sch[docid]["am"] || json.sch[docid]["pm"]))
								continue;

							for (t in time) {
								html += "<tr>";
								if (t == "am") {
									html += "<td rowspan=\"2\" class=\"pretitle\">";
									if (json.yuyue_to) {
										html += dRec.doctor_name;
									} else {
										html += "<a href=\""
												+ JYUrl("doc", "show", {
													"depid" : depid,
													"docid" : dRec.doctor_id
												})
												+ "\">"
												+ dRec.doctor_name
												+ "</a><br>"
												+ (dRec.zcname ? dRec.zcname
														: '');
									}
									html += "</td>";
									html += "<td height=\"35\">上午</td>";
								} else {
									html += "<td height=\"35\">下午</td>";
								}
								//
								for (d in json.date) {

									if (json.sch && json.sch[docid]
											&& json.sch[docid][t]
											&& json.sch[docid][t][d]) {
										var schRec = json.sch[docid][t][d];
										var leftNum = schRec.yuyue_max
												- schRec.yuyue_num;
										if (dRec.yuyue_type == "0"
												|| schRec.yuyue_max == 0
												|| schRec.open_yuyue != "1") {
											html += "<td>";
											html += "出诊";
										} else if (json.date[d] < json.span.yuyue_begin_date
												|| json.date[d] > json.span.yuyue_end_date) {
											html += "<td>";
											html += "出诊";
										} else if (schRec.yuyue_max > 0
												&& leftNum == 0) {
											html += "<td class=\"yuyue_full\">";
											html += "已约满";
										} else {
											html += "<td class=\"yuyue_d\">";
											var atitle = "总放号"
													+ schRec.yuyue_max
													+ "人次，已预约"
													+ schRec.yuyue_num + "人，诊金"
													+ dRec.guahao_amt + "元";
											if (dRec.doc_spec) {
												atitle += "&#13;诊疗范围："
														+ dRec.doc_spec;
											}
											if (schRec.sch_detl_show == 2) {
												html += "<a href=\""
														+ JYUrl(
																"guahao",
																"step3",
																{
																	uid : uid,
																	schid : schRec.schedule_id
																})
														+ "\" title=\""
														+ atitle
														+ "\"><p>预约</p><p>("
														+ schRec.yuyue_max
														+ ")</p></a>"
											} else {
												html += "<a href=\""
														+ JYUrl(
																"guahao",
																"step3",
																{
																	uid : uid,
																	schid : schRec.schedule_id
																})
														+ "\" title=\""
														+ atitle
														+ "\"><p>预约</p><p>("
														+ schRec.yuyue_num
														+ "/"
														+ schRec.yuyue_max
														+ ")</p></a>"
											}
										}
										html += "</td>";
									} else {
										html += "<td></td>";
									}

								}
								html += "</tr>";
							}
						}
						html += "</table>";
						$("#schmast").append(html);

					});
}

// 加载医生排班数据
function loadDoctorSchData(uid, depid, docid, bDate) {

	// var url =
	// JYUrl("doc","getschmast",{"uid":uid,"depid":depid,"docid":docid,"date":bDate});
	var url = sUrl = "http://" + location.hostname
			+ ":8080/ReserveSystemPortal" + "/doctor.json";
	var time = {
		"am" : "上",
		"pm" : "下"
	};

	$("#schmast").show();

	$("#paiban_doc td").html(
			"<p class=\"day\"></p><p class=\"am\"></p><p class=\"pm\"></p>");
	$("#paiban_doc tr").hide();
	$("#rt").show();

	var tblHtml = $("#schmast").html();
	// $("#schmast").html("<div class=\"ajax2login\" style=\"
	// height:400px;\">");

	$
			.getJSON(
					url,
					function(json) {

						// $("#schmast").html(tblHtml);

						$("#lastdate").val(json.last);
						$("#nextdate").val(json.next);
						$("#curr_a").text(json.mth);

						var html = "";
						var aNo = 1;

						for (r = 0; r <= json.erow; r++) {
							$("#r" + r).show();
							for (c = 0; c <= 6; c++) {
								if ((r == 0 && c < json.bcol)
										|| (r == json.erow && c > json.ecol)) {
									continue;
								}

								html = "<p class=\"day\">" + (aNo++) + "</p>";
								for (t in time) {

									var tag = "";

									if (json.sch && json.sch[r]
											&& json.sch[r][c]
											&& json.sch[r][c][t]) {
										var schRec = json.sch[r][c][t];
										var leftNum = schRec.yuyue_max
												- schRec.yuyue_num;
										if (schRec.yuyue_max == 0
												|| schRec.open_yuyue != "1")
											tag = "出诊";
										else if (schRec.date < json.span.yuyue_begin_date
												|| schRec.date > json.span.yuyue_end_date)
											tag = "出诊";
										else if (schRec.yuyue_max > 0
												&& leftNum == 0)
											tag = "已约满";
										else
											tag = "<a href=\""
													+ JYUrl(
															"guahao",
															"step3",
															{
																uid : uid,
																schid : schRec.schedule_id
															})
													+ "\" title=\"总放号"
													+ schRec.yuyue_max
													+ "人次，已预约"
													+ schRec.yuyue_num
													+ "人\"><img src=\"/images/img_yuyue.jpg\" width=\"39\" height=\"20\"></a>"

											// tag =
											// r+','+c+schRec.date.substr(8,2);
									}
									html += "<p class=\"" + t + "\">" + time[t]
											+ "：" + tag + "</p>";
								}
								$("#d" + r + c).html(html);
							}
						}
					});
}

function doSearchPaging(index)
{
	var skey = '<%=request.getAttribute("skey")%>';
	var url= '<%=contextPath%>/web2/indexAction.do?method=search&page=' + index;
	if(skey != '')
	{
		url += '&skey='+skey;
	}
	location.href = url;
}